package com.qyer.search.model.aggregation;

import com.qyer.search.cache.mutable.MutableCaches;

import java.util.*;

/**
 * Created by tangzheng on 16/8/9.
 */
public class ProductProject {

  private int lid;
  private long t_start_time;
  private long t_end_time;
  private long on_sale_time;
  private int travel_day;

  //private Map<Integer, Set<Integer>> destMap;
  private List<Integer> startCity;
  //各端stg,st,筛选项
  private Map<Integer, Map<Integer,VTYPEDES>> ztagMap;
  private List<Integer> poiList;

  private List<Integer> market_tag;
  private List<Integer> channel;
  private List<Integer> setOutPlace;
  private Map<Integer, Map<Integer, Set<Integer>>> destMap;
  private int marketInfo;
  private Set<Integer> maybeTags;

  public ProductProject(int lid, long t_start_time, long t_end_time, long on_sale_time,
                        int travel_day, List<Integer> startCity,
                        Map<Integer, Map<Integer, VTYPEDES>> ztagMap, List<Integer> poiList,
                        List<Integer> market_tag, List<Integer> channel, List<Integer> setOutPlace,
                        Map<Integer, Map<Integer, Set<Integer>>> destMap, int marketInfo,
                        Set<Integer> maybeTags) {
    this.lid = lid;
    this.t_start_time = t_start_time;
    this.t_end_time = t_end_time;
    this.on_sale_time = on_sale_time;
    this.travel_day = travel_day;
    this.startCity = startCity;
    this.ztagMap = ztagMap;
    this.poiList = poiList;
    this.market_tag = market_tag;
    this.channel = channel;
    this.setOutPlace = setOutPlace;
    this.destMap = destMap;
    this.marketInfo = marketInfo;
    this.maybeTags = maybeTags;
  }

  public ProductProject() {
  }

  public ProductProject(int lid) {
    this.lid = lid;
    marketInfo = Integer.MAX_VALUE;
    ztagMap = new HashMap<>();
    maybeTags = new HashSet<>();
    travel_day = 0;
  }

  public Set<Integer> getMaybeTags() {
    return maybeTags;
  }

  public void setMaybeTags(Set<Integer> maybeTags) {
    this.maybeTags = maybeTags;
  }

  public int getMarketInfo() {
    return marketInfo;
  }

  public void setMarketInfo(int marketInfo) {
    this.marketInfo = marketInfo;
  }

  public static ProductProject lid(int lid){
    return new ProductProject(lid);
  }

  public List<Integer> getSetOutPlace() {
    return setOutPlace;
  }

  public void setSetOutPlace(List<Integer> setOutPlace) {
    this.setOutPlace = setOutPlace;
  }

  public List<Integer> getChannel() {
    return channel;
  }

  public void setChannel(List<Integer> channel) {
    this.channel = channel;
  }

  public int getLid() {
    return lid;
  }

  public void setLid(int lid) {
    this.lid = lid;
  }

  public long getT_start_time() {
    return t_start_time;
  }

  public void setT_start_time(long t_start_time) {
    this.t_start_time = t_start_time;
  }

  public long getT_end_time() {
    return t_end_time;
  }

  public void setT_end_time(long t_end_time) {
    this.t_end_time = t_end_time;
  }

  public long getOn_sale_time() {
    return on_sale_time;
  }

  public void setOn_sale_time(long on_sale_time) {
    this.on_sale_time = on_sale_time;
  }

  public int getTravel_day() {
    return travel_day;
  }

  public void setTravel_day(int travel_day) {
    this.travel_day = travel_day;
  }

  public Map<Integer, Map<Integer, Set<Integer>>> getDestMap() {
    return destMap;
  }

  public void setDestMap(Map<Integer, Map<Integer, Set<Integer>>> destMap) {
    this.destMap = destMap;
  }

  public List<Integer> getStartCity() {
    return startCity;
  }

  public void setStartCity(List<Integer> startCity) {
    this.startCity = startCity;
  }

  public Map<Integer, Map<Integer, VTYPEDES>> getZtagMap() {
    return ztagMap;
  }

  public void setZtagMap(Map<Integer, Map<Integer, VTYPEDES>> ztagMap) {
    this.ztagMap = ztagMap;
  }

  public List<Integer> getPoiList() {
    return poiList;
  }

  public void setPoiList(List<Integer> poiList) {
    this.poiList = poiList;
  }

  public List<Integer> getMarket_tag() {
    return market_tag;
  }

  public void setMarket_tag(List<Integer> market_tag) {
    this.market_tag = market_tag;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    ProductProject that = (ProductProject) o;

    if (lid != that.lid)
      return false;
    if (t_start_time != that.t_start_time)
      return false;
    if (t_end_time != that.t_end_time)
      return false;
    if (on_sale_time != that.on_sale_time)
      return false;
    if (travel_day != that.travel_day)
      return false;
    if (!startCity.equals(that.startCity))
      return false;
    if (!ztagMap.equals(that.ztagMap))
      return false;
    if (!poiList.equals(that.poiList))
      return false;
    if (!market_tag.equals(that.market_tag))
      return false;
    if (!channel.equals(that.channel))
      return false;
    if (!setOutPlace.equals(that.setOutPlace))
      return false;
    return destMap.equals(that.destMap);

  }

  @Override public int hashCode() {
    int result = lid;
    result = 31 * result + (int) (t_start_time ^ (t_start_time >>> 32));
    result = 31 * result + (int) (t_end_time ^ (t_end_time >>> 32));
    result = 31 * result + (int) (on_sale_time ^ (on_sale_time >>> 32));
    result = 31 * result + travel_day;
    result = 31 * result + startCity.hashCode();
    result = 31 * result + ztagMap.hashCode();
    result = 31 * result + poiList.hashCode();
    result = 31 * result + market_tag.hashCode();
    result = 31 * result + channel.hashCode();
    result = 31 * result + setOutPlace.hashCode();
    result = 31 * result + destMap.hashCode();
    return result;
  }

  @Override public String toString() {
    return "ProductProject{" +
      "lid=" + lid +
      ", t_start_time=" + t_start_time +
      ", t_end_time=" + t_end_time +
      ", on_sale_time=" + on_sale_time +
      ", travel_day=" + travel_day +
      ", startCity=" + startCity +
      ", ztagMap=" + ztagMap +
      ", poiList=" + poiList +
      ", market_tag=" + market_tag +
      ", channel=" + channel +
      ", setOutPlace=" + setOutPlace +
      ", destMap=" + destMap +
      ", marketInfo=" + marketInfo +
      ", maybeTags=" + maybeTags +
      '}';
  }

  public ProductProject consDest(List<Integer> continent, List<Integer> country, List<Integer> city,
                        Map<Integer, Integer> city_country, Map<Integer, Integer> country_continent){
    Map<Integer,Map<Integer,Set<Integer>>> result = new HashMap<>();
    int size = city.size();
    int countryId = 0;
    int cityId = 0;
    int continentId = 0;
    for(int i = 0; i < size; i++){
      cityId = city.get(i);
      if(city_country.containsKey(cityId)){
        countryId = city_country.get(cityId);
      }else {
        continue;
      }
      if(country_continent.containsKey(countryId)){
        continentId = country_continent.get(countryId);
      }else {
        continue;
      }
      /////
      if(result.containsKey(continentId)){
        Map<Integer,Set<Integer>> map = result.get(continentId);
        if(map.containsKey(countryId)){
          map.get(countryId).add(cityId);
        }else {
          Set<Integer> set = new HashSet<>();
          set.add(cityId);
          map.put(countryId, set);
        }
      }else {
        Set<Integer> set = new HashSet<>();
        set.add(cityId);
        Map<Integer, Set<Integer>> map = new HashMap<>();
        map.put(countryId, set);
        result.put(continentId, map);
      }
      /////
    }
    ////////////////country
    size = country.size();
    for(int i = 0; i<size; i++){
      countryId = country.get(i);
      if(country_continent.containsKey(countryId)){
        continentId = country_continent.get(countryId);
        if(result.containsKey(continentId)){
          Map<Integer, Set<Integer>> map = result.get(continentId);
          if(!map.containsKey(countryId)){
            Set<Integer> set = new HashSet<>();
            map.put(countryId, set);
          }
        }else {
          Set<Integer> set = new HashSet<>();
          Map<Integer, Set<Integer>> map = new HashMap<>();
          map.put(countryId, set);
          result.put(continentId, map);
        }
      }else {
        continue;
      }
    }
    ////////////////////////////////////////////
    size = continent.size();
    Map<Integer,String> ccMap = MutableCaches.getInstance().CONTINENT_DICT.getCacheContent().getObverseDict();
    for(int i = 0; i < size; i++){
      continentId = continent.get(i);
      if(ccMap.containsKey(continentId)) {
        if (!result.containsKey(continentId)) {
          Map<Integer, Set<Integer>> map = new HashMap<>();
          result.put(continentId, map);
        }
      }
    }

    this.setDestMap(result);
    return this;
  }
}
